<cfcomponent>
<cffunction name="show" access="public" returntype="void" output="yes">
  <cfargument name="totalrecords" type="numeric" required="yes" hint="The total number of records to paginate">
  <cfargument name="disp" type="numeric" required="Yes" hint="how many to display">
  <cfargument name="start" type="numeric" required="Yes" hint="current start value">
  <cfargument name="page" type="numeric" required="Yes" hint="current page">
  <cfargument name="url" type="string" required="Yes" hint="url or javascript: myfucntion">
  <cfargument name="maxset" type="numeric" required="no" default="16" hint="current page">
  <cfargument name="displist" type="string" required="no" default="25,50,100,250" hint="comma delimited list of display options">

  <!---paginate.cfc by Jon Wallen (www.cfhowto.com)
  Open source and free to use, but do not distribute.  Please just link to my website if you want to share.
  
  USE:
  Include a link to the css file included with the cfc.
  On the page where you get a recordset set a variable for the total records.  Add the following <cfparam> tags to the top of the page:
  <cfparam name="start" default="1">
  <cfparam name="disp" default="25">
  <cfparam name="page" default="1">
  <cfset totalrecords = qmydbquery.recordcount> <!----this is an example replace with your totalrecords value---->
  
  Make the call to the cfc
  
	<cfinvoke component="cfcs.common.paginate" method="show" 
	start="#start#" 
	disp="#disp#" 
	totalrecords="#totalrecords#" 
	page="#page#" 
	url="index.cfm"
	maxset="12"
	/>
---> 
  
  <!---figure total number of pages--->
  <cfset pagecount = ceiling(totalrecords / disp)>
  
  <cfif pagecount GT 1>
  <cfset endblockstart = pagecount - 1>
  <cfset startblockstart = 1>
  <cfset prevpage = page - 1>
  <cfset nextpage = page + 1>
  <cfset prevstart = start - disp>
  <cfset nextstart = start + disp>
  <cfif url CONTAINS '?'>
  	<cfset url = "#url#&">
  <cfelse>
  	<cfset url = "#url#?">    
  </cfif>

  <cfset prevhref = "#url#disp=#disp#&page=#prevpage#&start=#prevstart#">
  <cfset nexthref = "#url#disp=#disp#&page=#nextpage#&start=#nextstart#">  
  <cfset currhref = "#url#">  

  <!---figure out which page to display first (depending on current page)--->
  <cfset showlastone = 0>
  <cfset showfirstone = 0>
  <cfif pagecount GT maxset>
	  <cfset midset = ceiling(maxset / 2)>
      <cfif page LT midset>
		<cfset maxset = maxset - 2><!---commensates for last page showing with ...--->
        <cfset pagestart = 1>
        <cfset pageend = maxset>
	    <cfset showlastone = 1>
      </cfif>
      <cfif page IS midset>
        <cfset maxset = maxset - 2>
		<cfset showlastone = 1>
        <cfset pagestart = 1>
        <cfset pageend = maxset>
      </cfif>
      <!---if we are over the middle of the set begin shifting start and end page--->
      <cfif page GT midset>
		<cfset pageend = page + midset - 2>
        <cfset showfirstone = 1>
        <cfset showlastone = 1>
        <!--- if the ending page is over the pagecount set it to the count and then pad the start page to keep 
        equal number of pages showing--->
        <cfif pageend GT pagecount>
        	<cfset showlastone = 0>
            <cfset pagepad = pageend - pagecount>
            <cfset pageend = pagecount>
            <cfset pagestart = page - (midset + pagepad) + 1>
        <cfelse>
            <cfset pagestart = page - midset + 3>
        </cfif>
      </cfif>
  <cfelse>
  	<cfset pagestart = 1>
    <cfset pageend = pagecount>
  </cfif>
  <cfif pagestart IS 1>
  	<cfset recstart = 1>
  <cfelse>
  	<cfset recstart = (disp * pagestart) - disp>
  </cfif>
	<cfset lastrecstart = (disp * pagecount) - disp>
  <cfset firsthref = "#url#disp=#disp#&page=1&start=1">
  <cfset lasthref = "#url#disp=#disp#&page=#pagecount#&start=#lastrecstart#">

<div id="pagination">
<span class="pageslist">
  <cfoutput><a <cfif page GT 1>href = "#prevhref#"</cfif> <cfif prevstart LT 1>class="disabled"</cfif>>&laquo; Previous</a></cfoutput> 
  <cfif showfirstone IS 1><a href = "#firsthref#">&nbsp;1</a><span>..</span></cfif>
  <cfloop from="#pagestart#" to="#pageend#" index="p"> 
  <cfset linkhref = "#url#disp=#disp#&page=#p#&start=#recstart#">
  <cfset recstart = recstart + disp>
<cfoutput>
<a href = "#linkhref#" <cfif p IS page>class="selected"</cfif>><cfif len(trim(p)) LT 2>&nbsp;</cfif>#p#</a>
</cfoutput>
  </cfloop>
  <cfif showlastone IS 1><span>..</span><a href = "#lasthref#"><cfif len(trim(pagecount)) LT 2>&nbsp;</cfif>#pagecount#</a></cfif>
  <cfoutput><a <cfif page LT pagecount>href = "#nexthref#"</cfif> <cfif page GTE pagecount>class="disabled"</cfif>>&raquo; Next</a></cfoutput>
<span>&nbsp;</span><span>Per Page:</span><cfloop list="#displist#" index="d">
<cfoutput><a href = "#currhref#disp=#d#&start=1&page=1" <cfif d IS disp>class="selected"</cfif>>#d#</a></cfoutput></cfloop>
</span>	
<span class="clear"></span>
</div>
</cfif><!---end if page count is greater than 1--->
</cffunction>
</cfcomponent>
